const app = getApp();
import {request} from '../../utils/request'
import config from '../../utils/config'

Page({
    data: {
        picUrl: config.picUrl,
        goodList:[],
        page:1,
        last_page:1,
        endHide:true,
        custom: {top:null,bottom:null,height:null,left:null,right:null,width:null},

    },
    onLoad(options) {
        this.setData({
            custom: wx.getMenuButtonBoundingClientRect(),
            user:wx.getStorageSync('userInfo')
        })
        this.getList()
    },
    getList() {
        request({
            url:"/miniprogram/order/getSoleOrderList",
            data:{
                page:this.data.page,
                limit:10,
                user_id:this.data.user.id
            },
            type:'post'
        }).then(res=>{
            if(res.code !== 0){
                wx.showToast({title:res.msg,icon:'none'})
                return false
            }
            if(this.data.page == 1){
                this.setData({goodList:[]})
            }
            this.setData({
                goodList:this.data.goodList.concat(res.data),
                last_page:res.last_page
            })
        })
    },
    back() {
        wx.navigateBack({delta:1})
    },
    onPullDownRefresh() {
    },
    onReachBottom() {
        if(this.data.page >= this.data.last_page){
            this.setData({endHide:false})
            return false
        }
        this.setData({page:this.data.page+1})
        this.getList()
    },
    handle(e){
        var {id,status,order,pay} = e.currentTarget.dataset
        switch (status){
            case 2:
                //审核拒绝的剧本，提示是否删除
                wx.showModal({
                    title:'是否删除该意向申请信息？',
                    success:rel=>{
                        request({
                            url:'/miniprogram/order/delSoleOrder',
                            data:{id,order_id:order},
                            type:'post'
                        }).then(res=>{
                            config.toast(res.msg,201,()=>{
                                if(res.code == 200){
                                    this.setData({page:1})
                                    this.getList()
                                }
                            })
                        })
                    }
                })
                break;
            case 0:
                config.toast("发行商正在审核中，请等待审核通过后再进行购买。",201,()=>{})
                break;
            case 1:
                wx.navigateTo({url:"/pages/order_detail/order_detail?id="+order})
                break;
        }
    },
    naviGood(e){
        var info = wx.getStorageSync('userInfo')
        //authentication_type 认证类型3-发行商，4-商户，5-普通访客
        //is_authentication 是否经过系统认证，0-未认证；1-审核中；2-审核通过；3-审核被拒
        if(info.is_wechat_authentication != 1){
            wx.showModal({
                title:'提示',
                content:"您还未登录或注册，请先登录",
                cancelText:"取消",
                confirmText:"登录",
                success:res=>{
                    if(res.confirm){
                        wx.switchTab({url:"/pages/my/my"})
                    }else{

                    }
                }
            })
            return false
        }
        if(info.authentication_type == 5){
            wx.showModal({
                title:'提示',
                content:"您还未进行身份认证，请先认证您身份信息",
                cancelText:"认证商户",
                confirmColor:"#000",
                confirmText:"认证发行",
                success:res=>{
                    if(res.confirm){
                        wx.navigateTo({url:"/pages/faxingrenzheng/faxingrenzheng"})
                    }else{
                        wx.navigateTo({url:"/pages/shanghurenzheng/shanghurenzheng"})
                    }
                }
            })
            return false;
        }
        if(info.is_authentication != 2){
            config.toast("您的身份审核暂未通过，请等待审核通过",201,()=>{})
            return false
        }
        wx.navigateTo({url:e.currentTarget.dataset.url})
    },
})